package com.situ.day1;

import java.util.Scanner;

import org.junit.Test;

public class Homework {

	public static void main(String[] args) {
		// 第1题
		Scanner scanner = new Scanner(System.in);
		System.out.println("请随机输入两个数：");
		int num1 = scanner.nextInt();
		int num2 = scanner.nextInt();
		// 打印原来的两个数
		System.out.println("num1=" + num1);
		System.out.println("num2=" + num2);
		// 两个数交换
		int temp = 0;
		temp = num1;
		num1 = num2;
		num2 = temp;
		// 打印交换后的两个数
		System.out.println("After Change:num1=" + num1);
		System.out.println("After Change:num2=" + num2);
	}

	@Test
	public void test2() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("单价：");
		double price = scanner.nextDouble(); // 单价
		System.out.println("数量：");
		double num = scanner.nextDouble(); // 数量
		System.out.println("所收金额：");
		double amount = scanner.nextDouble(); // 顾客所付金额
		// 输入的单价，数量，金额小于零时，输出错误信息
		if ((price < 0) || (num < 0) || (amount < 0)) {
			System.out.println("输入错误，请重新输入");
			return;
		}
		double totalPrice = price * num; // 应收金额
		// 当总价>=500时，打八折
		if (totalPrice >= 500) {
			totalPrice = totalPrice * 0.8;
			System.out.println("应收金额：" + totalPrice);
		} else {
			System.out.println("应收金额：" + totalPrice); // 总价不足500
		}
		double change; // 找零
		if (amount >= totalPrice) { 
			change = amount - totalPrice; // 所收金额大于等于总价，进行找零
			System.out.println("找零：" + change);
		} else {
			System.out.println("所收金额不足！"); // 所收金额小于应收金额
		}
	}

}
